<!doctype html>
<html>
<head>
  <meta charset="utf-8"/>
  <title>Marked in the browser</title>
  <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
  <style>
    #content {
      width: 1000px;
      margin: 0 auto;
      box-shadow: inset 0px 0px 1px 0px;
      box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
      padding: 20px;
      margin-top: 50px;
    }
    #content h1 {
      text-align: center;
    }
    #content code {
      display: inline-block;
      background-color: #96bb96;
      border-radius: 4px;
      padding: 10px;
    }
  </style>
</head>
<body>
  <input type="file" name="file" id="file" />
  <div id="content"></div>
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> 
  <script src="https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script>
  <!-- <link href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.12.0/build/styles/default.min.css"> -->
  <!-- <link href="https://cdn.bootcss.com/highlight.js/9.12.0/styles/monokai-sublime.min.css" rel="stylesheet"> -->
  <link href="https://cdn.bootcss.com/highlight.js/9.12.0/styles/monokai.min.css" rel="stylesheet">
  <!-- <link href="https://cdn.bootcss.com/github-markdown-css/2.10.0/github-markdown.min.css" rel="stylesheet"> -->
  <script>
    /**   
     *  marked.js简易手册
     *  https://www.cnblogs.com/djtao/p/6224399.html
     *  
     *  highlight.js CDN
     *  https://www.bootcdn.cn/highlight.js/
     */
    marked.setOptions({
      renderer: new marked.Renderer(),
      gfm: true,
      tables: true,
      breaks: false,
      pedantic: false,
      sanitize: false,
      smartLists: true,
      smartypants: false,
      highlight: function (code) {
        return hljs.highlightAuto(code).value;
      }
    });

    $(function() {
      $("#file").on("change", function(e) {
        // console.log(e);
        // console.log(e.target.files);
        // console.log(e.target.files[0]);

        var reader = new FileReader();
        // reader.readAsDataURL(e.target.files[0]);
        // reader.readAsBinaryString(e.target.files[0]);
        reader.readAsText(e.target.files[0])
        reader.onload = function(e) {
          // console.log(e.target.result); 
          var tmp = marked(e.target.result)

          console.log(tmp); 

          $('#content').html(tmp)
        };
      });


    });
  </script>
</body>
</html>